package com.huangguolin.cloud.recycle.control;

import com.huangguolin.cloud.file.entity.SearchFileEntity;
import com.huangguolin.cloud.mybatis.entity.PtFileEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PadingRstEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.recycle.repository.RecycleDao;
import com.huangguolin.cloud.recycle.service.RecycleService;
import com.huangguolin.cloud.spring.control.BaseController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/recycle")
public class RecycleController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private RecycleService recycleService;

    @RequestMapping("/fileRecycle")
    public String fileRecycle() {
        return "recycle/fileRecycle";
    }

    @RequestMapping("/queryFileListByPage")
    @ResponseBody
    public PadingRstEntity<PtFileEntity> queryFileListByPage(SearchFileEntity entity, PagingEntity paging) {
        logger.info(entity);
        PadingRstEntity<PtFileEntity> list = recycleService.queryFileListByPage(entity, paging);
        return list;
    }

    @RequestMapping("/deleteFile")
    @ResponseBody
    public String deleteFile(@RequestParam("fileUuid") String fileUuid) {
        recycleService.deleteFile(fileUuid);
        return successJSON("delete.file.success");
    }

    @RequestMapping("/restoreFile")
    @ResponseBody
    public String restoreFile(@RequestParam("fileUuid") String fileUuid) {
        recycleService.restoreFile(fileUuid);
        return successJSON("file.restore.success");
    }
}


